//
//  ClassLayout.m
//  BeautyClother
//
//  Created by dllo on 15/8/25.
//  Copyright (c) 2015年 宋爽. All rights reserved.
//

#import "ClassLayout.h"

@interface ClassLayout ()

@property (nonatomic, assign) CGFloat offWidth;
@property (nonatomic, assign) CGFloat offHeight;

@end
@implementation ClassLayout

- (void)dealloc
{
    [super dealloc];
    
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.array = [NSMutableArray array];
        self.layarr = [NSMutableArray array];
        self.offWidth = [[UIScreen mainScreen]bounds].size.width / 375;
        self.offHeight = [[UIScreen mainScreen]bounds].size.height / 667;
    }
    return self;
}

- (void)prepareLayout
{
    [super prepareLayout];
    [self cacul];
}

- (void)cacul
{
    NSInteger num = [self.collectionView numberOfItemsInSection:0];
    for (int i = 0; i <num; i++) {
        NSIndexPath *index = [NSIndexPath indexPathForItem:i inSection:0];
        UICollectionViewLayoutAttributes *atts = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:index];
        atts.frame = CGRectMake(i % 3 * 90 * _offWidth + 10 *_offWidth,  i / 3 * 120 *_offHeight + 10 *_offHeight, 80 *_offWidth, 100 *_offHeight);
        [self.array addObject:atts];
    }
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
     NSMutableArray *arr = [NSMutableArray array];
    for (UICollectionViewLayoutAttributes *att in self.array) {
        
        if (CGRectContainsRect(att.frame, rect) || CGRectIntersectsRect(att.frame, rect)) {
            [arr addObject:att];
        }
        
    }
    return arr;
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.array objectAtIndex:indexPath.item];
}

- (CGSize)collectionViewContentSize
{
   
    return CGSizeMake(275 *_offWidth, self.height);
    
}

@end
